<?php

//左边列表函数
function goods_list($type_id){
	//$children=get_children($type_id);
	$sql="SELECT * FROM ". $GLOBALS['os']->table('category') . " WHERE parent_id='$type_id' and is_show=1 limit 20";
	$res = $GLOBALS['db']->getAll($sql);
    $arr = array();    
    foreach ($res AS $idx => $row)
    {	 
      $arr[$idx]['cat_name']= $row['cat_name'];
	  $arr[$idx]['url']="category.php?id=".$row['cat_id']."";
    }
    return $arr;    
}


//男女热卖函数
function goods_hot($type_id){
global $_CFG;
$children=get_children($type_id);
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.sales_type, g.goods_img ' .
            'FROM ' . $GLOBALS['os']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['os']->table('member_price') . ' AS mp ' .
                "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
            "WHERE $children and g.is_hot='1' ORDER BY g.goods_id desc limit 10";        
$res = $GLOBALS['db']->getAll($sql);
    $arr = array();
    foreach ($res AS $idx => $row)
    {
	 
      $arr[$idx]['goods_name']= $row['goods_name'];
      $arr[$idx]['goods_thumb']      = $_CFG['pre_fetch_img'].get_image_path($row['goods_id'], $row['goods_thumb'], true);
      $arr[$idx]['goods_img']        = $_CFG['pre_fetch_img'].get_image_path($row['goods_id'], $row['goods_img']);
	  $arr[$idx]['url']=build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
    }
    return $arr;
}
 
//列表页菜单
function list_order($cat_id){
	$arr=array();	
	if ($cat_id>0) 
	{			   
	    for($i=0;$i<=$cat_id;$i++)
	    {
	    	if ($cat_id==1 || $cat_id==2) {
	    		return $cat_id;
	    		break;
	    	}
	    	
	    	$sql="SELECT parent_id FROM ".$GLOBALS['os']->table('category')." WHERE cat_id = '$cat_id'";	    	
	    	$cat_id=$GLOBALS['db']->getOne($sql);	
	    	//print_r($cat_id."<BR>");   
	    	//$arr[$i]=array($cat_id);
	    	//echo $cat_id;
	    	if ($cat_id==2 || $cat_id==1)
	    	{
	    		return $cat_id;
	    		break;
	    	}
	    }
	}
	   

}
?>